clc,clear
z=readmatrix("E:\课题组学习资料\侯义惠师兄\滚子试验\g1-1-1.xlsx"); %读入初始形貌
%z=z*10^3;
[numx,numy]=size(z); %计算初始形貌矩阵的行列数

delta_dg=1.9*10^(-6); %采样间距delta_dg微米（手动输入）

%%计算工件抛光前表面粗糙度
zabs_original=abs(z); %将抛光前的形貌矩阵取绝对值
Ra_origianl=sum(sum(zabs_original))/(numx*numy); %计算抛光前的Ra

Lx=numx*delta_dg; %计算采样区域长度
Ly=numy*delta_dg; %计算采样区域宽度


%%在采用区域内，等间距取numx/numy个采样点
xx=linspace(0,delta_dg*numx*10^6,numx);
yy=linspace(0,delta_dg*numy*10^6,numy);

z_ave=sum(sum(z))/(numx*numy);
z_norm=z-z_ave*ones(numx,numy);

figure(1)
[xx1,yy1]=meshgrid(xx,yy);  %生成采样点的网格矩阵
surf(xx1,yy1,z_norm,'EdgeColor','interp');  %生成初始表面形貌
zlim([-2 2]); %纵坐标范围[-2,2]
view(-60,80);  %调整视角
title('实验形貌图');
colorbar;

% xticks([0 100 200 300 400 500 600 700]);
% xticklabels({'0','100','200','300','400','500','600','700'});
% Sa0=mean(abs(z(:)))
% 
% surf(xx,yy,z_norm,'EdgeColor','interp'),view(126,80);c = colorbar;c.Location = 'eastoutside';
% title(sprintf('Sa=%0.3fum',Sa0));
% 
% set(gca,'fontsize',10,'fontname','Times New Roman');
% ax = gca;
% axpos = ax.Position;
% c.Position(3) = 0.5*c.Position(3);
% ax.Position = axpos;